package com.example.spring.boot.business.user.impl;

import com.example.spring.boot.business.user.CreateUserBusiness;
import com.example.spring.boot.repository.user.UserEntity;
import com.example.spring.boot.repository.user.UserMapper;
import com.example.spring.boot.business.user.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class CreateUserBusinessImpl implements CreateUserBusiness {

    @Autowired
    UserMapper userMapper  = null;

    @Autowired
    CreateUserBusinessConvert createUserBusinessConvert;
    public UserMapper getUserMapper() {
        return userMapper;
    }

    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    public CreateUserBusinessConvert getCreateUserBusinessConvert() {
        return createUserBusinessConvert;
    }

    public void setCreateUserBusinessConvert(CreateUserBusinessConvert createUserBusinessConvert) {
        this.createUserBusinessConvert = createUserBusinessConvert;
    }

    @Override
    public UserModel createUser(UserModel userModel) {
        UserEntity userEntity = this.createUserBusinessConvert.toUserEntity(userModel);
        this.userMapper.createUser(userEntity);
        this.createUserBusinessConvert.toUserModel(userEntity,userModel);
      //  if(true){throw new RuntimeException("11");}
        this.createUserBusinessConvert.toUserModel(userEntity,userModel);
        return userModel;
    }
}
